<%-- 
    Document   : calendar
    Created on : 09.03.2011, 23:30:16
    Author     : mike
--%>

<%@page import="com.google.code.gfcalendar.GfCalendar"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.GregorianCalendar"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/calendar/css/calendar.css" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Жефко - Календарь</title>
  </head>
  <body>
    <%@include file="/common/navigator.jsp" %>
<%
  String dateMY = request.getParameter("dateMY");
  int year;
  int month;
  if (dateMY != null && !dateMY.isEmpty())
  {
     year = Integer.parseInt(dateMY.substring(dateMY.indexOf('-')+1));
     month = Integer.parseInt(dateMY.substring(0, dateMY.indexOf('-')));
  }
  else
  {
    Calendar now = GregorianCalendar.getInstance();
    year = now.get(Calendar.YEAR);
    month = now.get(Calendar.MONTH);
  }
  GfCalendar calendar = new GfCalendar(month, year);
  GfCalendar.DateMY nextMonth = calendar.getCurrentMonth().getNextMonth();
  GfCalendar.DateMY prevMonth = calendar.getCurrentMonth().getPreviousMonth();
%>
<%= calendar.getCurrentMonth().getMonth()%> <%= calendar.getCurrentMonth().getYear()%>
    <form action="/calendar/calendar.jsp" method="post">
      <input type="hidden" name="dateMY" value="<%= prevMonth.getMonth()%>-<%= prevMonth.getYear()%>"/>
      <input type="submit" value="prev"/>
    </form>
    <form action="/calendar/calendar.jsp" method="post">
      <input type="hidden" name="dateMY" value="<%= nextMonth.getMonth()%>-<%= nextMonth.getYear()%>"/>
      <input type="submit" value="next"/>
    </form>
    <div class="main-container">
<%
  String boxid;
  do
  {
    if (calendar.isOtherMonth())
    {
      boxid = "other";
    }
    else
    if (calendar.isWeekEnd())
    {
      boxid = "hol";
    }
    else
    {
      boxid = "work";
    }
%>
    <div class="box" id="<%= boxid%>">
      <span class="date"><%= calendar.getDate()%></span>
    </div>
<%
  }
  while (calendar.hasNext());
  %>
    </div>
  </body>
</html>
